import {PageHandler} from "@/modules/IDE/pageHandler";

const ide = {
  state: {
    imageAssetsList: [], // 图片资源列表
    activeTheme: [
      {key: "bg-color-container", value: "#FFFFFF", label: "主要容器背景"},
      {key: "bg-component", value: "#EBECF2", label: "组件背景"},
      {key: "bg-color-page", value: "#F0F1F5", label: "默认页面背景"},
      {key: "bg-color-secondarypage", value: "#F7F8FA", label: "容器背景"},
      {key: "component-stroke", value: "#DADCE5 ", label: "边框/分割线"},
      {key: "text-color-primary", value: "#000000 ", label: "主要文字"},
      {key: "text-color-secondary", value: "#454859 ", label: "次要文字"},
      {key: "text-color-placeholder", value: "#8A8EA6 ", label: "提示文字"},
      {key: "text-color-disabled", value: "#B4B8CC ", label: "不可用文字"},
      {key: "text-color-anti", value: "#FFFFFF ", label: "反色文字"},
      {key: "brand-color", value: "#2D69E0 ", label: "品牌色"},
      {key: "error-color", value: "#F25644 ", label: "错误色"},
      {key: "success-color", value: "#26BF7F ", label: "成功色"},
      {key: "warning-color", value: "#FAAD14 ", label: "警告色"}
    ], // 当前激活主题配置
    globalDeviceList: [], // 设备列表
    globalCommandList: {}, // 命令列表
    globalVarList: [], // 全局变量列表
    globalLogicList:[], // 真值反馈列表
    globalScenesList: [], // 组合命令列表
    curPageType: 'page', // 当前编辑区展示的是主页还是子页 page/subPage
    curPageTypeForPicker: 'page', // 组件选择器当前展示的是主页还是子页 page/subPage
    curPageHandler: new PageHandler('page'), // 当前编辑区展示的主页数据源
    curSubPageHandler: new PageHandler('subPage'), // 当前编辑区展示的子页数据源
    freezeMode: false, // 是否开启冻结模式，不可更改所有组件的 rect 信息
    draggingWidget: undefined, // 当前被拖拽进行创建的组件
    draggingDeviceWidget: undefined, // 当前被拖拽进行创建的小组件
    pointerPosition: {}, // 当前鼠标的坐标，包括拖动创建组件时的 drag event 和组件点击时的 click event
    selectWidgetIds: [], // 当前被选中的 widget id 集合
    widgetAxis: 'both', // 组件允许移动的轴，默认 x，y 轴都允许拖动
    selectionBoxRect: {}, // 多选框位置
    showWidgetPage:false,//展示小组件页面
    widgetPickerInfo: { // 记录全局组件选择器当前状态
      show: false,
      pickerId: '',
      selectWidgetId: ''
    },
  },
  mutations: {
    imageAssetsList(state, imageAssetsList) {
      state.imageAssetsList = imageAssetsList;
    },
    activeTheme(state, activeTheme) {
      state.activeTheme = activeTheme;
    },
    globalDeviceList(state, globalDeviceList) {
      state.globalDeviceList = globalDeviceList;
    },
    globalCommandList(state, globalCommandList) {
      state.globalCommandList = globalCommandList;
    },
    globalVarList(state, globalVarList) {
      state.globalVarList = globalVarList;
    },
    globalLogicList(state, globalLogicList) {
      state.globalLogicList = globalLogicList;
    },
    globalScenesList(state, globalScenesList) {
      state.globalScenesList = globalScenesList;
    },
    curPageType(state, curPageType) {
      state.curPageType = curPageType;
    },
    curPageTypeForPicker(state, curPageTypeForPicker) {
      state.curPageTypeForPicker = curPageTypeForPicker;
    },
    curPageHandler(state, curPageHandler) {
      state.curPageHandler = curPageHandler;
    },
    curSubPageHandler(state, curSubPageHandler) {
      state.curSubPageHandler = curSubPageHandler;
    },
    freezeMode(state, freezeMode) {
      state.freezeMode = freezeMode;
    },
    draggingWidget(state, draggingWidget) {
      state.draggingWidget = draggingWidget;
    },
    draggingDeviceWidget(state, draggingDeviceWidget) {
      state.draggingDeviceWidget = draggingDeviceWidget;
    },
    pointerPosition(state, pointerPosition) {
      state.pointerPosition = pointerPosition;
    },
    selectWidgetIds(state, selectWidgetIds) {
      state.selectWidgetIds = selectWidgetIds;
    },
    widgetAxis(state, widgetAxis) {
      state.widgetAxis = widgetAxis;
    },
    selectionBoxRect(state, selectionBoxRect) {
      state.selectionBoxRect = selectionBoxRect;
    },
    widgetPickerInfo(state, widgetPickerInfo) {
      state.widgetPickerInfo = widgetPickerInfo;
    },
    showWidgetPage(state, showWidgetPage) {
      state.showWidgetPage = showWidgetPage;
    },
  },
  actions: {
    updateImageAssetsList({commit}, imageAssetsList) {
      commit("imageAssetsList", imageAssetsList);
    },
    updateGlobalVarList({commit}, globalVarList) {
      commit("globalVarList", globalVarList);
    },
    updateGlobalCommandList({commit}, globalCommandList)  {
      commit("globalCommandList", globalCommandList);
    },
    updateActiveTheme({commit}, activeTheme) {
      commit("activeTheme", activeTheme);
    },
    updateGlobalScenesList({commit}, globalScenesList) {
      commit("globalScenesList", globalScenesList);
    },
    updateGlobalDeviceList({commit}, globalDeviceList) {
      commit("globalDeviceList", globalDeviceList);
    },
    updateGlobalLogicList({commit}, globalLogicList) {
      commit("globalLogicList", globalLogicList);
    },
    updateCurPageType({commit}, curPageType) {
      commit("curPageType", curPageType);
    },
    updateCurPageTypeForPicker({commit}, curPageTypeForPicker) {
      commit("curPageTypeForPicker", curPageTypeForPicker);
    },
    updateCurPageHandler({commit}, curPageHandler) {
      commit("curPageHandler", curPageHandler);
    },
    updateCurSubPageHandler({commit}, curSubPageHandler) {
      commit("curSubPageHandler", curSubPageHandler);
    },
    updateFreezeMode({commit}, freezeMode) {
      commit("freezeMode", freezeMode);
    },
    updateDraggingWidget({commit}, draggingWidget) {
      commit("draggingWidget", draggingWidget);
    },
    updateDraggingDeviceWidget({commit}, draggingDeviceWidget) {
      commit("draggingDeviceWidget", draggingDeviceWidget);
    },
    updatePointerPosition({commit}, pointerPosition) {
      commit("pointerPosition", pointerPosition);
    },
    updateSelectWidgetIds({commit}, selectWidgetIds) {
      commit("selectWidgetIds", selectWidgetIds);
    },
    updateWidgetAxis({commit}, widgetAxis) {
      commit("widgetAxis", widgetAxis);
    },
    updateSelectionBoxRect({commit}, selectionBoxRect) {
      commit("selectionBoxRect", selectionBoxRect);
    },
    updateWidgetPickerInfo({commit}, widgetPickerInfo) {
      commit("widgetPickerInfo", widgetPickerInfo);
    },
    updateShowWidgetPage({commit}, showWidgetPage) {
      commit("showWidgetPage", showWidgetPage);
    },
  },
};

export default ide;
